<template>
    <view class="outOrderList" style="padding-top: 80rpx">
        <view class="table-td" v-for="(item,index) in chuKuOrderList" :key="index">
            <!-- <view class="iconBtn">
                <u-icon v-if="!item.isShow" name="arrow-down" color="#000" size="24" @click="btnShow(true, item)"></u-icon>
                <u-icon v-if="item.isShow" name="arrow-up" color="#000" size="24" @click="btnShow(false, item)"></u-icon>
            </view> -->
            <uni-collapse>
            <uni-collapse-item>
                <template v-slot:title>
                <view class="chanshishuju" style="margin:0 10rpx 0 6rpx;font-size: 30rpx;">
                    <view style="font-weight:bold;font-size: 30rpx" v-if="type !== '1'">
                      <text :selectable="true">站址编码：{{ item.siteId }}</text>
                    </view>
                    <view style="font-weight:bold;font-size: 30rpx">
                      <text :selectable="true">物料编码：{{ item.categoryCode }}</text>
                    </view>
                    <view style="font-weight:bold;font-size: 30rpx">
                      <text :selectable="true">物料名称：{{ item.materialName || item.categoryName }}</text>
                    </view>
                </view>
                </template>
                <view class="list-body" style="font-size: 27rpx;color: #AFAEAC;margin: 0;">
                <view style="display: flex">
                    <view class="chanshishuju-center" style="font-size: 27rpx;color: #AFAEAC">
                    <text class="t1">出库数量：</text>
                    <text class="t2">{{ item.amount }}</text>
                    </view>
                    <view class="chanshishuju-center" style="font-size: 27rpx;color: #AFAEAC">
                    <text class="t1">申请退库数量：</text>
                    <text class="t2">{{ item.retreatAmount }}</text>
                    </view>
                </view>
                <view class="chanshishuju-center" style="font-size: 27rpx;color: #AFAEAC">
                    <text class="t1">完成退库数量：</text>
                    <text class="t2">{{ item.retreatRealAmount }}</text>
                </view>
                <view class="chanshishuju-buttom">
                    <view v-if="getEdit(item)">
                        <button style="width:180rpx ;height:50rpx;font-size: 26rpx;line-height: 50rpx"
                                type="warn" size="mini"
                                @click.stop="shenqingkuiku(index, item)">
                            申请退库
                        </button>
                    </view>
                    <view v-if="+item.retreatAmount > +item.retreatRealAmount && getEdit(item)">
                        <button style="width:180rpx ;height:50rpx;font-size: 26rpx;line-height: 50rpx"
                                type="warn" size="mini"
                                @click.stop="chexiaokuiku(item)">
                            撤销退库
                        </button>
                    </view>
                    <view v-if="+item.retryButton === 1 && getEdit(item)">
                        <button style="width:180rpx ;height:50rpx;font-size: 26rpx;line-height: 50rpx"
                                type="warn" size="mini"
                                @click.stop="syncWarehousing(item)">
                            同步仓储
                        </button>
                    </view>
                    <!--出库数量大于0且为试点地市贴签赋码主设备物资时-->
                    <view v-if="+item.assetLabelNum > 0">
                        <button style="width:230rpx ;height:50rpx;font-size: 26rpx;line-height: 50rpx"
                                type="warn" size="mini"
                                @click.stop="checkOutboundDetail(item)">
                            查看贴签明细
                        </button>
                    </view>
                </view>
                </view>
            </uni-collapse-item>
            </uni-collapse>
        </view>
        <!-- 提示 -->
        <view style="width: 100%;padding: 10rpx 0;text-align: center;background-color:#00000008; color:#737373 ;margin: 15rpx 0;">
            ---没有更多了---
        </view>
    </view>
</template>

<script>
export default {
    props: {
        type: {
            type: String,
            default: ''
        },
        chuKuParams: {
            type: Object,
            default: () => ({})
        },
        chuKuOrderList: {
            type: Array,
            default: () => []
        },
        prjInfo: {
          type: Object,
          default: () => ({})
        },
    },
    methods: {
        getEdit(item){
          console.log(this.prjInfo,item.jwMateRetreat)
          if(this.prjInfo.acceptcheck === '1'){
            return +this.prjInfo.isNewAcceptance === 1 && +item.jwMateRetreat === 1
          }else{
            return this.prjInfo.isEdit === '1'
          }
        },
        // 申请退库
        shenqingkuiku(e, item) {
            const { bundingId, amount, retreatAmount, labelCodeAmount, pcBanNum, canRetreatAmount } = item
            const { prjId } = this.chuKuParams
            if (!+pcBanNum && !+canRetreatAmount) {
                return uni.showModal({
                    title: "温馨提示",
                    content: "可退库数量为0不可进行退库操作",
                    confirmColor:'#eb4b4b',
                    showCancel: false
                });
            }
            if (+pcBanNum && !+canRetreatAmount) {
                return uni.showModal({
                    title: "温馨提示",
                    content: "该物资不能使用常规退库，请使用【扫码退库】功能退有签有码资源",
                    confirmColor:'#eb4b4b',
                    showCancel: false
                });
            }
            console.log("出库数量=" + amount);
            console.log("申请数量=" + retreatAmount);
            console.log("有钱有吗数量=" + labelCodeAmount);
            console.log("是否是示范点=" + uni.getStorageSync('isPilotUnit'));
            if (uni.getStorageSync('isPilotUnit') == "0") {
                uni.navigateTo({
                url: './tuikushenqing?index=' + e + '&prjId=' + prjId + '&type=' + this.type + '&bangdingId=' + bundingId + "&item=" +
                    encodeURIComponent(JSON.stringify(item)),
                });
            } else {
                let jieguo = Number(amount) - Number(retreatAmount) - Number(labelCodeAmount)
                console.log("计算数量=" + jieguo);
                uni.navigateTo({
                    url: './tuikushenqing?index=' + e + '&prjId=' + prjId + '&type=' + this.type + '&bangdingId=' + bundingId +
                        '&jieguo=' + jieguo + "&item=" +
                        encodeURIComponent(JSON.stringify(item)),
                })
            }
        },
        //同步仓储
        syncWarehousing(item){
            let that=this;
            this.$axios.post('/material/api/material/transfer/appSendMaterialTransferInfo?osDetailId='+item.osDetailId).then((res)=>{
                uni.showModal({
                    title: '温馨提示',
                    content: res.message,
                    confirmColor: '#eb4b4b',
                    showCancel: false,
                    success: function () {
                        that.$emit('changeList')
                    }
                })
            })
        },
        // 撤销退库
        chexiaokuiku(item) {
            uni.navigateTo({
                url: './tuikuList?bundingId=' + item.bundingId + '&type=' + this.type + '&osDetailId=' + item.osDetailId
            });
        },
        // 查看贴签明细
        checkOutboundDetail(item) {
            const { bundingId } = item
            const { prjId } = this.chuKuParams
            console.log(bundingId, item, 'itemitem')
            uni.navigateTo({
                url: './outboundMaterialDetail?bangdingId=' + bundingId + '&prjId=' + prjId + '&type=' + this.type + "&item=" +
                    encodeURIComponent(JSON.stringify(item))
            });
        }
    }
}
</script>

<style lang="scss" scoped>
@import "@/common/common-ui.css";
.table-td {
    width: 95%;
    background-color: #fff;
    margin: 20rpx auto;
    border-radius: 20rpx;
    box-sizing: border-box;
    // padding: 20rpx 15rpx 20rpx 15rpx;
    overflow: auto;
    background-color: white;
    color: black;
    text-align: left;

    .chanshishuju {
    padding: 10rpx 4% 10rpx 20rpx;
    width: 100%;

    .chanshishuju-center {
        display: flex;
        width: 100%;
        // color: #000000c1;

        .t1 {
        white-space: nowrap;
        }
    }
    .chanshishuju-buttom {
        width: 100%;
        display: flex;
        justify-content: space-between;
    }
    }

    .list-body {
    width: 100%;
    padding: 0rpx 5% 0rpx 80rpx;
    background-color: white;
    color: #737373;

    .chanshishuju-center {
        display: flex;
        width: 100%;
        color: #737373;
    }

    .chanshishuju-buttom {
        padding-top: 15rpx;
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        flex-wrap: wrap;
    }
    }
}
</style>